<?php

namespace App\Jobs;

use App\Models\Mysql\XnSupplierGoods;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldBeUnique;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\DB;

class SupplierGoodsTImePrice implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    private $data;
//    public $tries = 3;
    public function __construct($data = [])
    {
        $this->data = $data;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        $da = [
            'unit_price'=>$this->data['unit_price'],//进货价
            'price'=>$this->data['price'],//销售价
            'max_price'=>$this->data['max_price'],//价格上线
        ];
        $redis = new \redis();
        $redis->connect('127.0.0.1', 6379);//连接redis
        $key = $this->data['business_number'].'SupplierGoodsTImePrice'.$this->data['id'];
        $info = $redis->get($key);
        if (empty($info)){
            echo  '修改已被撤销';
        }else{
            $res = DB::connection($this->data['db'])
                ->table('xn_supplier_goods')
                ->where('id',$this->data['id'])
                ->update($da);
            if ($res){
                $redis->del($key);
            }
        }
    }
}
